﻿using Lwk.MyLife.Core.Helpers;
using Lwk.MyLife.Dtos;
using Newtonsoft.Json;

namespace Lwk.MyLife.Controllers;
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
    private readonly ILogger<ValuesController> _logger;
    private readonly IHttpClientHelper _httpClientHelper;

    public ValuesController(ILogger<ValuesController> logger
        , IHttpClientHelper httpClientHelper)
    {
        _httpClientHelper = httpClientHelper;
        _logger = logger;
    }
    // GET: api/<ValuesController>
    [HttpGet]
    public IEnumerable<string> Get()
    {
        _logger.LogInformation("有了吗！！！");
        return new string[] { "value1", "value2" };
    }

    // GET api/<ValuesController>/5
    [HttpGet("{id}")]
    public async Task<IActionResult> Get(int id)
    {
        #region 测试httpclient
        var model = new { id = "3" };
        var result =await _httpClientHelper.CustomerPostAsync("http://localhost:5117/api/values/test_post", JsonConvert.SerializeObject(model));
        #endregion
        return Ok(result);
    }

    [HttpPost("test_post")]
    public IActionResult Post([FromBody] TestDto testDto)
    {
        return Ok(testDto.Id);
    }


    // PUT api/<ValuesController>/5
    [HttpPut("{id}")]
    public void Put(int id, [FromBody] string value)
    {
    }

    // DELETE api/<ValuesController>/5
    [HttpDelete("{id}")]
    public void Delete(int id)
    {
    }
}
public class TestModel
{
    public string mKey { get; set; }
    public string mValue { get; set; }
}
